package nuc.soft.A01.jzs.services.problem;

import java.util.ArrayList;

import nuc.soft.A01.jzs.dao.problem.SimpleMapper;
import nuc.soft.A01.jzs.model.problem.ManyChooseProblem;
import nuc.soft.A01.jzs.model.problem.SimpleCommit;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import tool.Tools;


@Service
public class SimpleService {

	@Autowired
	private SimpleMapper dao;
	
	public int insert(SimpleCommit problem)
	{
		problem.setId(Tools.getUUID());
		return dao.insert(problem);
	}
	
	public int update(SimpleCommit problem)
	{
		return dao.update(problem);
	}
	
	public int delete(SimpleCommit problem)
	{
		return dao.delete(problem);
	}
	
	public int deleteById(String id)
	{
		return dao.deleteById(id);
	}
	
	public int deleteById(SimpleCommit problem)
	{
		return dao.deleteById(problem.getId());
	}
	
	public ArrayList<SimpleCommit>	getAllSimple()
	{
		return (ArrayList<SimpleCommit>) dao.getAllObject();
	}
	
	
	public ArrayList<SimpleCommit> getSearchManyChoose(String search)
	{
		ArrayList<SimpleCommit> allproblem=this.getAllSimple();
		ArrayList<SimpleCommit> searchproblem=new ArrayList<SimpleCommit>();
		for(SimpleCommit problem:allproblem)
		{
			if(problem.getQuestion().contains(search))
			{
				searchproblem.add(problem);
			}
		}
		return searchproblem;
	}
	
	public SimpleCommit getASimpleById(String id)
	{
		return (SimpleCommit) dao.getAObjectById(id);
	}
}
